// JavaScript Document
define(function (require, exports, module) {
	
	var ListItem=function(selector,num,options){
		this.element=$(selector).get(0);
		this.num=num;
		this.options=options;
	}
	ListItem.prototype.target="";
	//绑定控件
	ListItem.prototype.bindControl=function(){
		var self=this;
		
		this.selectButton=$(this.element).find(".select *:first-child").eq(0)
		this.selectButton.unbind()
		this.selectButton.bind("click",function(event){self.selectButtonClickHandle(event)})
		
		this.removeButton=$(this.element).find(".remove *:first-child").eq(0)
		this.removeButton.unbind()
		this.removeButton.bind("click",function(event){self.removeButtonClickHandle(event)})

	}
	ListItem.prototype.getSelectButtonIsVisible=function(){
		return this.selectButtonVisible=$(".select .button",this.element).is(":visible")
	}
	//选择按钮点击
	ListItem.prototype.selectButtonClickHandle=function(event){
		this.options.appendById(this.getId());
	}
	//移除按钮点击
	ListItem.prototype.removeButtonClickHandle=function(event){
		this.options.removeById(this.getId());
	}
	
	//getValueByClassName 根据className获得
	ListItem.prototype.getValueByClassName=function(className){
		var value=$(this.element).find("[class='"+className+"']").get(0).innerHTML;
		return value;
	}
	//获得id
	ListItem.prototype.setId=function(id){
		this.id=id;
	}
	/*ListItem.prototype.getId=function(){
		this.id=$(this.element).find("*[name='id']").get(0).value;
		return this.id;
	}*/
	ListItem.prototype.getId=function(){
		this.id=$(".id",this.element).get(0).innerHTML;
		return this.id;
	}
	
	
	//获得id
	ListItem.prototype.setIdName=function(idName){
		this.idName=idName;
	}
	ListItem.prototype.getIdName=function(){
		this.idName=$("[class='idName']",this.element).val();
		if(this.idName==""){
			this.idName=$("[class='idName']",this.element).html();
		}
		return this.idName;
	}
	
	//设置编号
	ListItem.prototype.setSn=function(sn){
		this.sn=sn;
		var snElement=$(".index",this.element).get(0);
		if(typeof snElement =="undefined"){
			snElement=this.element.children[0];
		}
		snElement.innerHTML=sn+1;
	}
	ListItem.prototype.getSn=function(){
		return this.sn;
	}
	//选择
	ListItem.prototype.select=function(){
		$(this.element).addClass("selected");
		$(this.selectButton).html("已选择")
		this.selectedState=true;
	}
	//取消选择
	ListItem.prototype.deselect=function(){
		$(this.element).removeClass("selected");
		$(this.selectButton).html("选择")
		this.selectedState=false;
	}
	
	//取消选择
	ListItem.prototype.deselect=function(){
		$(this.element).removeClass("selected");
		$(this.selectButton).html("选择")
		this.selectedState=false;
	}
	
	
	
	ListItem.MODE_TR_REMOVE="trRemoveMode"
	ListItem.MODE_LI_REMOVE="liRemoveMode"
	
	ListItem.prototype.setMode=function(mode){
		this.mode=mode;
		/*if(mode==ListItem.MODE_TR_REMOVE){
			var element=$(this.element).find("[class='operation']").get(0);
			element.innerHTML="<a class=\"removeButton\">移出</a>";
			this.update()
		}*/
	}
	
	
	module.exports = ListItem;
});